package com.sh.data.engine.domain.integration.api.webservice.model.domain;

import com.sh.data.engine.domain.base.model.BaseDomain;
import com.sh.data.engine.domain.integration.api.taskconfig.model.domain.TaskConfigDomain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Date;
import java.util.List;

/**
 * @author : changkong
 * @date : 2022/3/15
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class TaskDomain extends BaseDomain {

    private Long id;

    private String taskName;

    private Date startTime;

    private Date endTime;
    // api相关
    private TestAPiWsRequest apiWsRequest;

    private PreviewExpressRequest previewExpressRequest;

    // 任务配置相关
    private TaskConfigDomain taskConfigRequest;

    private String dataxJobScript;

    // 任务运行状态
    private Integer taskStatus;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TestAPiWsRequest {

        private String protocol;

        private String address;

        private String addressUserNameKey;

        private String addressUserNameValue;

        private String addressPasswordKey;

        private String addressPasswordValue;

        private String service;

        private String port;

        private String operation;

        private String localClassPath;

        // 认证参数
        private ApiHttpAuthParam apiWsAuthParam;

        // 请求头
        //    private ApiHttpRequestHeaderParam apiHttpRequestHeaderParam;

        // 请求体
        private ApiHttpRequestBodyParam apiWsRequestBodyParam;

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class ApiHttpAuthParam {
            // 认证方式    noauth, basic, sign, token
            private String authType;

            // basic
            private String authUsername;

            private String authPassword;

            // sign
            private String accessKey;

            private String accessSecret;

            // token
            private String accessToken;

            // 资源路径
            private String jarUrl;

            private String advancedCacheKey;
            // jar包名
            private String advancedFileName;
            // 资源路径
            private String advancedFilePath;

            private String advanceClassReference;

            private String advanceMethodName;

            // 变量有效期
            private Date expires;
        }

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class ApiHttpRequestHeaderParam {
            // 请求头列表
            private List<Header> params;

            /**
             * 请求头
             */
            @Data
            @NoArgsConstructor
            @AllArgsConstructor
            public static class Header {
                // 消息头名称
                private String name;
                // 具体值
                private String value;
            }
        }

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class ApiHttpRequestBodyParam {

            private String contentType;
            // 请求体
            private String body;

            // url参数
            private List<FormParam> formParams;

            @Data
            @NoArgsConstructor
            @AllArgsConstructor
            public static class FormParam {

                /**
                 * 参数类型 0-输入参数 1-返回参数
                 */
                private Integer paramType;

                /**
                 * 参数名称
                 */
                private String paramName;

                /**
                 * 参数位置 query head body
                 */
                private String paramPosition = "query";

                /**
                 * 参数数据类型
                 */
                private String paramDataType;

                /**
                 * 参数值
                 */
                private String paramValue;

                /**
                 * 描述
                 */
                private String paramDesc;

                /**
                 * 返回参数取值表达式
                 */
                private String paramExpression;

                /**
                 * 参数属性 0-无(纯输入值) 1-pageNo 2-pageSize
                 */
                private Integer paramAttribute = 0;
            }
        }
    }

    /**
     * 预览接口请求参数
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class PreviewExpressRequest {

        private String responseRawJson;
        // 要解析的jsonPath表达式列表

        private List<ExpressionParam> expressionParamList;

        // js脚本
        private String jsScript;

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class ExpressionParam {
            // 用户填写的名称
            private String name;

            // jsonPath表达式
            private String expression;

            // 层级关系
            private Integer relationship;
        }
    }
}
